package com.chenbei.common.util;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;

/**
 * 日期工具类
 */
public class DateUtil {

    /**
     * Date转LocalDateTime
     * @param date 日期
     * @return LocalDateTime
     */
    public static LocalDateTime toLocalDateTime(Date date) {
        ZoneId zoneId = ZoneId.of("Asia/Shanghai");
        if (date == null) {
            throw new IllegalArgumentException("Date must not be null");
        }

        return date.toInstant().atZone(zoneId).toLocalDateTime();
    }

    /**
     * Date转LocalDate
     * @param date 日期
     * @return LocalDate
     */
    public static LocalDate toLocalDate(Date date) {
        ZoneId zoneId = ZoneId.of("Asia/Shanghai");
        if (date == null) {
            throw new IllegalArgumentException("Date must not be null");
        }
        return date.toInstant().atZone(zoneId).toLocalDate();
    }
}
